﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBQLTV;

namespace DAO
{
    public class ThongKeMuonSachDAO
    {
        public THONGKEMUONSACH InsertThongKeMuonSach(int Thang, int Nam)
        {
            using (DBQUANLYTHUVIENEntities entity = new DBQUANLYTHUVIENEntities())
            {
                THONGKEMUONSACH thongke = entity.THONGKEMUONSACHes.FirstOrDefault(o => o.Thang == Thang && o.Nam == Nam);
                if (thongke == null)//create new
                {
                    THONGKEMUONSACH tk = new THONGKEMUONSACH()
                    {
                        Thang = Thang,
                        Nam = Nam,
                        TongLuotMuon = 0
                    };
                    entity.THONGKEMUONSACHes.AddObject(tk);
                    entity.SaveChanges();
                    return tk;
                }
                else
                {
                    return thongke;
                }

            }
        }
        public THONGKEMUONSACH GetThongKeMuonSach(int Thang, int Nam)
        {
            using (DBQUANLYTHUVIENEntities entity = new DBQUANLYTHUVIENEntities())
            {
                THONGKEMUONSACH thongke = entity.THONGKEMUONSACHes.FirstOrDefault(o => o.Thang == Thang && o.Nam == Nam);
                return thongke;
            }
        }
    }
}
